﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using Extentions;
using TrainingReminderSystem.Bll;
using TrainingReminderSystem.Model;

namespace TrainingReminderSystem.ApiControllers
{
    /// <summary>
    /// 客户机构培训记录模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    public partial class SysCustomerOrganizationTrainController : BaseControllerBase
    {
        #region 客户机构培训记录

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        /// [Route("api/SysCustomerOrganizationTrain/List")]
        [HttpPost]
        public async Task<AjaxResult<List<SysCustomerOrganizationTrainExList>>> List([FromForm] IFormCollection form)
        {
            var bll = new SysCustomerOrganizationTrainBll();
            var result = await bll.GetListByPage(PageIndex(form), PageSize(form), form);
            return result;
        }
        
        /// <summary>
        /// 得到对象信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        /// [Route("api/SysCustomerOrganizationTrain/Get")]
        [HttpGet]
        public async Task<AjaxResult<dynamic>> Get(int id)
        {
            var bll = new SysCustomerOrganizationTrainBll();
            var ar = await bll.GetModel(id);
            dynamic model = ar.Result;
            return AjaxResult<dynamic>.SuccessResult(model);
        }

        /// <summary>
        /// 新建/编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// [Route("api/SysCustomerOrganizationTrain/Save")]
        [HttpPost]
        public async Task<AjaxResult<dynamic>> Save(SysCustomerOrganizationTrainExPost model)
        {
            var bllModel = new SysCustomerOrganizationTrain();
            bllModel = bllModel.ExCopyFrom(model);
            var bll = new SysCustomerOrganizationTrainBll();
            var r = await bll.Save(bllModel);
            return r;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        /// [Route("api/SysCustomerOrganizationTrain/Del")]
        [HttpPost]
        public async Task<AjaxResult<dynamic>> Del([FromForm] IFormCollection form)
        {
            var bll = new SysCustomerOrganizationTrainBll();
            var r = await bll.Del(form["id"].ExToInt32());
            return r;
        }
        
        /// <summary>
        /// 下拉查询
        /// </summary>
        /// <param name="form"></param>
        /// <returns></returns>
        /// [Route("api/SysCustomerOrganizationTrain/ListSelect")]
        [ExOnlyValidateSysEmployee]
        [HttpPost]
        public async Task<AjaxResult<List<SysCustomerOrganizationTrain>>> ListSelect([FromForm] IFormCollection form)
        {
            var bll = new SysCustomerOrganizationTrainBll();
            var result = await bll.GetListSelect(form);
            return result;
        }

        #endregion
    }
}
